<?php

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use App\Models\ConfigGood;
use Encore\Admin\Controllers\AdminController;

class ConfigGoodsController extends AdminController
{
    protected $title = '秒杀红包配置';
    
    protected function form()
    {
        $form = new Form(new ConfigGood());

        $form->currency('goods_total_price', '可抢购商品总价')->symbol('￥')->default(0);
         $form->currency('user_quota', '用户可抢额度')->symbol('￥')->default(0);
       
        $form->rate('goods_incr_percent', '商品增长比例')->default(125);
        $form->rate('lowest_amount_percent', '红包最小比例')->default(95);
        $form->rate('highest_amount_percent', '红包最大比例')->default(99.99);
       
        $form->timeRange('start_at', 'end_at', '抢购时间范围');
         $form->number('destory_time', '未付款过期时间')->default(300)->help('NOTE:此处为秒级');
        
        
        $this->formTools($form);
        $this->formSaved($form);
        $this->formFooter($form);

        return $form;
    }
	
	protected function formTools(Form $form)
	{
		$form->tools(function (Form\Tools $tools) {
			$tools->disableList();
			$tools->disableView();
			$tools->disableDelete();
		});
	}
	
	protected function formSaved(Form $form)
	{
		$form->saved(function () {
			admin_toastr('秒杀红包配置已更新', 'success');
			return redirect(route('admin.config-goods.edit', 1));
		});
	}
	
	protected function formFooter(Form $form)
	{
		$form->footer(function (Form\Footer $footer) {
			$footer->disableViewCheck();
			$footer->disableCreatingCheck();
			$footer->disableEditingCheck();
		});
	}
}
